<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Source extends Auth_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('source_mdl');
    }

    public function s_create(){
        if(!$this->input->is_ajax_request()){
            show_404();
        }

        $title = $this->input->post('title');
        if(empty($title)){
            die('来源标题不能为空');
        }

        $this->db->where('title',$title);
        $this->db->select('id');
        $res = $this->source_mdl->get_one();

        if(!empty($res)){
            echo $res['id'];
        }else{

            $data = array(
                'title' => $title,
                'create_time' => $_SERVER['REQUEST_TIME'],
                'user_id' => $_SESSION['user']['id']
            );

            $c_id = $this->source_mdl->create($data);
            //echo $this->db->last_query();
            echo $c_id;

        }
    }

}

/* End of file Source.php */
/* Location: ./application/controllers/Source.php */